home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / SAT / Collision ƒ / SATcollision.c < prev    next >
Encoding:
Text File  |  1994-07-26  |  1.6 KB  |  70 lines  |  [TEXT/KAHL]

  1.  
  2. //• C translation from Pascal source file: SATcollision.p
  3.  
  4. //• *****************************.
  5. //• ********* SAT Collision **********.
  6. //• *****************************.
  7.  
  8. //• A SAT demo that is slightly over SATminimal, demonstrating the simplest.
  9. //• collision handling based on the kind field (KindCollision)..
  10.  
  11. //• main SATcollision;
  12.  
  13. #include "SAT.h"
  14. #include "Collision.h"
  15. //, sMrEgghead, sApple;
  16.  
  17.     
  18. SpritePtr ignoreSp;
  19. long l;
  20. Point p;
  21.  
  22. main ()
  23. {
  24.     MaxApplZone ();
  25.     FlushEvents (everyEvent - diskMask, 0 );
  26.     InitGraf (&thePort);
  27.     InitFonts ();
  28.     InitWindows ();
  29.     InitMenus ();
  30.     TEInit ();
  31.     InitDialogs (nil);        /* no restart proc */
  32.     InitCursor ();
  33.  
  34.     MoreMasters ();
  35.     MoreMasters ();
  36.  
  37. //• Initialize SAT.
  38.     ConfigureSAT(true, kVPositionSort, kKindCollision, 32);
  39.     InitSAT(128, 129, 512, 322);
  40.  
  41. //• Initialize sprite units.
  42.     InitMrEgghead ();
  43.     InitApple ();
  44.  
  45. //• Show and update the window.
  46.     ShowWindow(gSAT.wind);
  47.     SelectWindow(gSAT.wind);
  48.     PeekOffscreen ();
  49.  
  50. //• Make sprites.
  51.     GetMouse(&p); //• We get the mouse position in order to put Mr Egghead under it immediately.
  52.     ignoreSp = NewSprite(0, p.h, p.v, &HandleMrEgghead, &SetupMrEgghead, 0L);
  53.     ignoreSp = NewSprite(0, 0, Rand(gSAT.offSizeV - 32), &HandleApple, &SetupApple, 0L);
  54.  
  55.     HideCursor();
  56.  
  57.     do
  58.         {
  59.         l = TickCount ();
  60.         RunSAT(true); //• Run a frame of animation.
  61.         while ( l > TickCount () - 3 ) //• Speed limit.
  62.             ;
  63.  
  64. //• Start a new apple once in a while.
  65.         if ( Rand(40) == 1 )
  66.             ignoreSp = NewSprite(0, 0, Rand(gSAT.offSizeV - 32), &HandleApple, &SetupApple, 0L);
  67.     } while (! Button ());
  68.     ShowCursor ();
  69.     SATSoundShutup (); //• Always make sure the sound channel is de-allocated!.
  70. }